package com.java3_1;

public class Clerk {
    private int product;

    public Clerk() {

    }

    public Clerk(int product) {
        this.product = product;
    }

    public int getProduct() {
        return product;
    }

    public void setProduct(int product) {
        this.product = product;
    }

    public void productAdd() {
        synchronized (this) {
            if (product < 20) {
                product++;
                System.out.println("生产了一个商品,这是第" + product + "个商品");
                notify();
            } else {
                try {
                    wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

        }
    }

    public void productDelete() {
        synchronized (this) {
            if (product > 0) {
                product--;
                System.out.println("消耗了一个商品,这是第" + product + "个商品");
                notify();
            } else {
                try {
                    wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

        }
    }
}
